const cloud = require('wx-server-sdk')
const axios = require('axios')
cloud.init({
  env: cloud.DYNAMIC_CURRENT_ENV
})

exports.main = async (event) => {
  try {
    const { date, is_time_accurate } = event
    
    const response = await axios.post('https://ejj.vip.cpolar.cn/get_lucky_color', {
      date,
      is_time_accurate
    }, {
      headers: { 'Content-Type': 'application/json' },
      timeout: 5000
    })
    
    return {
      code: 200,
      data: response.data
    }
  } catch (error) {
    const statusCode = (error.response && error.response.status) || 500;
    return {      
      // code: error.response?.status || 500,
      code:statusCode,
      message: error.message,
      data: null
    }
  }
}